package com.xmutca.chapter1.step4;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {

	private String name;
	
	private Vector<Rental> rentals = new Vector<>();

	public Customer(String name) {
		super();
		this.name = name;
	}

	public void addRental(Rental rental) {
		rentals.add(rental);
	}

	public String getName() {
		return name;
	}

	public String statement() {
		double totalAmount = 0;
		int frequentRenterPoints = 0;
		Enumeration<Rental> rentalEnus = rentals.elements();
		String result = "*Rental Record for " + getName() + "\n";
		while (rentalEnus.hasMoreElements()) {
			double thisAmount = 0;
			Rental rental = (Rental) rentalEnus.nextElement();

			thisAmount = rental.getCharge();

			frequentRenterPoints ++;
			if (rental.getMovie().getPriceCode() == Movie.NEW_RELEASE
					&& rental.getDaysRented() > 1) {
				frequentRenterPoints++;
			}
			
			result += "\t" + rental.getMovie().getTitle() + "\t" + thisAmount + "\n";
			totalAmount += thisAmount;
		}
		
		result += "Amount owed is " + totalAmount + "\n";
		result += "You earned " + frequentRenterPoints + "frequent renter points";
		return result;
	}
}
